import { fileURLToPath, URL } from 'node:url'
import vuetify from 'vite-plugin-vuetify'
import svgLoader from 'vite-svg-loader'

// https://nuxt.com/docs/api/configuration/nuxt-config
export default defineNuxtConfig({
  compatibilityDate: "2024-11-01",
  devtools: { enabled: true },
  // 固化项目配置
  runtimeConfig: {
    // 私有配置（仅服务端可访问）
    jwtSecret: process.env.JWT_SECRET,
    jwtExpiresIn: process.env.JWT_EXPIRES_IN,
    // 公共配置（客户端和服务端都可访问）
    public: {
      cookie: {
        secure: process.env.NODE_ENV === 'production',
        sameSite: 'strict',
        maxAge: process.env.JWT_EXPIRES_IN,
      },
      app: {
        nodeEnv: process.env.NODE_ENV || 'development',
        isProd: process.env.NODE_ENV === 'production',
        isDev: process.env.NODE_ENV === 'development',
      }
    }
  },
  vite: {
    resolve: {
      alias: {
        "@core": fileURLToPath(new URL("./@core", import.meta.url)),
        "@layouts": fileURLToPath(new URL("./@layouts", import.meta.url)),
        "@images": fileURLToPath(new URL("./assets/images/", import.meta.url)),
        "@styles": fileURLToPath(new URL("./assets/styles/", import.meta.url)),
        "@configured-variables": fileURLToPath(
          new URL("./assets/styles/variables/_template.scss", import.meta.url)
        ),
      },
    },
    build: {
      chunkSizeWarningLimit: 5000,
    },
    optimizeDeps: {
      exclude: ["vuetify"],
      entries: ["./**/*.vue"],
    },
    plugins: [
      svgLoader(),
      vuetify({
        styles: {
          configFile: 'assets/styles/variables/_vuetify.scss',
        },
      }),
    ],
  },
  // 注册全局插件
  plugins: [
    "~/plugins/auth.js",
    "~/plugins/types.ts",
    "~/plugins/toast.js",
    "@/plugins/vuetify/index.js",
    "@/plugins/iconify/index.js",
  ],
  // TypeScript配置
  typescript: {
    strict: true,
    typeCheck: true,
    shim: false,
  },
  nitro: {
    preset: "cloudflare_module",
    cloudflare: {
      deployConfig: true,
      nodeCompat: true,
    },
  },
  build: {
    transpile: ['vuetify'],
  },
  modules: ["nitro-cloudflare-dev", "@vueuse/nuxt", "@pinia/nuxt"],
});
